/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package com.lxk.oms.order.listener;


import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.lxk.event.oms.OrderPaySuccessEvent;
import com.lxk.event.oms.enums.OrderEnums;
import com.lxk.oms.order.domain.req.CommentOrderReq;
import com.lxk.oms.order.domain.req.ConfirmOrderReq;
import com.lxk.oms.order.domain.req.SendOrderReq;
import com.lxk.oms.order.manger.OrderManger;
import com.lxk.oms.order.service.IOmsOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 订单支付成功监听
 *
 * @author heyi
 * 2024/9/24
 */
@Component
@Slf4j
@AllArgsConstructor
public class OrderPaySuccessListener {
    private final IOmsOrderService omsOrderService;
    private final OrderManger orderManger;

    /**
     * @param event
     */
    @DSTransactional(rollbackFor = Exception.class)
    @EventListener
    public void orderPaySuccess(OrderPaySuccessEvent event) {
        Integer orderType = event.getOrderType();
        Long userId = event.getUserId();
        String orderNo = event.getOrderNo();
        if (OrderEnums.OrderType.VIRTUAL_TYPE_CODE.contains(orderType)) {
            SendOrderReq req = new SendOrderReq();
            req.setSendOptionEvent(false);
            req.setOrderNo(orderNo);
            orderManger.sendOrder(req);
            ConfirmOrderReq req1 = new ConfirmOrderReq();
            req1.setOrderNo(orderNo);
            req1.setUserId(userId);
            req1.setSendOptionEvent(false);
            orderManger.confirmOrder(req1);
            CommentOrderReq req2 = new CommentOrderReq();
            req2.setOrderNo(orderNo);
            req2.setUserId(userId);
            req2.setComment("默认好评");
            orderManger.commentOrder(req2);
        }

    }
}
